<?php

namespace common\models;

use Yii;
use yii\db\ActiveRecord;
use common\models\base\BaseModel;

/**
 * This is the model class for table "article".
 *
 * @property integer $id
 * @property string $title
 * @property string $summary
 * @property string $content
 * @property string $label_img
 * @property integer $cat_id
 * @property integer $user_id
 * @property string $user_name
 * @property integer $is_valid
 * @property integer $created_at
 * @property integer $updated_at
 */
class ArticleModel extends BaseModel
{
    /**
     * 定义文章是否发布的常量
     * @var unknown
     */
    const IS_VALID = 1;
    const NO_VALID = 0;
    
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'article';
    }
    
    public function getRelate()
    {
        return $this->hasMany(RelationTagsArt::className(), ['art_id' => 'id']);
    }
    
    public function getExtend()
    {
        return $this->hasOne(PostExtendsModel::className(), ['post_id' => 'id']);
    }
    
    public function getCat()
    {
        return $this->hasOne(Cate::className(), ['id' => 'cat_id']);
    }
    

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['content'], 'string'],
            [['cat_id', 'user_id', 'is_valid', 'created_at', 'updated_at'], 'integer'],
            [['title', 'summary', 'label_img'], 'string', 'max' => 255],
            [['user_name'], 'string', 'max' => 50],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => '编号',
            'title' => '标题',
            'summary' => '摘要',
            'content' => '正文',
            'label_img' => '标签图',
            'cat_id' => '分类',
            'user_id' => '用户编号',
            'user_name' => '用户名',
            'is_valid' => '是否发布',
            'created_at' => '创建时间',
            'updated_at' => '修改时间',
        ];
    }
}
